package com.china08.yxyapi.api.home.kecheng.cloud.ques;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.entity.db.lessons.cloud.YxyLessonsCloudLessonItemQues;
import com.china08.yxyapi.model.YxyApiReqModel;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.db.lesson.YxyLessonsCloudLessonItemQuesRepository;

/**
 * 
 * @annotation: 云课程--查询课程对应试题ID
 * @author: yaoguanglin
 */
@CrossOrigin
@RestController
public class KechengCloudQuesIdSrhController extends YxyApiBaseController {

    @Autowired
    private YxyLessonsCloudLessonItemQuesRepository yxyLessonsCloudLessonItemQuesRepository;

    @RequestMapping(value = "/api_yw/home/kecheng/cloud/ques/id/srh", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public RespModel precess(HttpServletRequest request, HttpServletResponse response,
            @RequestBody(required = false) ReqModel reqModel) {

        String itemId = reqModel.itemId;

        List<YxyLessonsCloudLessonItemQues> lessonItemId = yxyLessonsCloudLessonItemQuesRepository
                .findByLessonItemId(itemId);
        RespModel model = new RespModel();
        List<String> quesIds = new ArrayList<String>();
        if (lessonItemId != null && lessonItemId.size() > 0) {
            for (YxyLessonsCloudLessonItemQues yxyLessonsCloudLessonItemQues : lessonItemId) {
                quesIds.add(yxyLessonsCloudLessonItemQues.getQuesId());
            }
        }
        model.quesIds = quesIds;
        return model;
    }

    protected static class ReqModel extends YxyApiReqModel {
        // 课时ID
        public String itemId;
    }

    protected static class RespModel extends YxyApiRespModel {
        // 试题ID
        public List<String> quesIds;
    }
}
